﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Models
{
    [Serializable]
    public class AuthorInfo
    {
        public int ID { get; set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string AuthorName { get; set; }
        /// <summary>
        /// 密码
        /// </summary>
        public string AuthorPassword { get; set; }
        /// <summary>
        /// 角色
        /// </summary>
        public int RoleID { get; set; }
        /// <summary>
        /// 头像地址
        /// </summary>
        public string AuthorImageUrl { get; set; }
        /// <summary>
        /// 博客地址
        /// </summary>
        public string BlogUrl { get; set; }
        /// <summary>
        /// 创建时间
        /// </summary>
        public DateTime? CreateTime { get; set; }

        public AuthorInfo(int id, string authorName, string authorPassword, int roleID, string authorImageUrl, string blogUrl, DateTime? createTime)
        {
            this.ID = id;
            this.AuthorName = authorName;
            this.AuthorPassword = authorPassword;
            this.RoleID = roleID;
            this.AuthorImageUrl = authorImageUrl;
            this.BlogUrl = blogUrl;
            this.CreateTime = createTime;
        }

        public AuthorInfo(DataTable dataTable)
        {
            if (ModelHelper.HasColumn(dataTable, "id"))
            {
                this.ID = Convert.ToInt32(dataTable.Rows[0]["id"].ToString());
            }
            if (ModelHelper.HasColumn(dataTable, "authorName"))
            {
                this.AuthorName = (string)dataTable.Rows[0]["authorName"];
            }
            if (ModelHelper.HasColumn(dataTable, "authorPassword"))
            {
                this.AuthorPassword = (string)dataTable.Rows[0]["authorPassword"];
            }
            if (ModelHelper.HasColumn(dataTable, "roleID"))
            {
                this.RoleID = (int)dataTable.Rows[0]["roleID"];
            }
            if (ModelHelper.HasColumn(dataTable, "authorImageUrl"))
            {
                this.AuthorImageUrl = (string)dataTable.Rows[0]["authorImageUrl"];
            }
            if (ModelHelper.HasColumn(dataTable, "blogUrl"))
            {
                this.BlogUrl = (string)dataTable.Rows[0]["blogUrl"];
            }
            if (ModelHelper.HasColumn(dataTable, "CreateTime"))
            {
                this.CreateTime = (DateTime)dataTable.Rows[0]["createTime"];
            }

        }


    }
}
